home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / win32com / client / selecttlb.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  5.6 KB  |  159 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''Utilities for selecting and enumerating the Type Libraries installed on the system
  5. '''
  6. import win32api
  7. import win32con
  8. import string
  9.  
  10. class TypelibSpec:
  11.     
  12.     def __init__(self, clsid, lcid, major, minor, flags = 0):
  13.         self.clsid = str(clsid)
  14.         self.lcid = int(lcid)
  15.         self.major = int(major)
  16.         self.minor = int(minor)
  17.         self.dll = None
  18.         self.desc = None
  19.         self.ver_desc = None
  20.         self.flags = flags
  21.  
  22.     
  23.     def __getitem__(self, item):
  24.         if item == 0:
  25.             return self.ver_desc
  26.         
  27.         raise IndexError, 'Cant index me!'
  28.  
  29.     
  30.     def __cmp__(self, other):
  31.         if not self.ver_desc:
  32.             pass
  33.         if not other.ver_desc:
  34.             pass
  35.         rc = cmp(string.lower(''), string.lower(''))
  36.         if rc == 0:
  37.             rc = cmp(string.lower(self.desc), string.lower(other.desc))
  38.         
  39.         if rc == 0:
  40.             rc = cmp(self.major, other.major)
  41.         
  42.         if rc == 0:
  43.             rc = cmp(self.major, other.minor)
  44.         
  45.         return rc
  46.  
  47.     
  48.     def FromTypelib(self, typelib, dllName = None):
  49.         la = typelib.GetLibAttr()
  50.         self.clsid = str(la[0])
  51.         self.lcid = la[1]
  52.         self.major = la[3]
  53.         self.minor = la[4]
  54.         if dllName:
  55.             self.dll = dllName
  56.         
  57.  
  58.  
  59.  
  60. def EnumKeys(root):
  61.     index = 0
  62.     ret = []
  63.     while 1:
  64.         
  65.         try:
  66.             item = win32api.RegEnumKey(root, index)
  67.         except win32api.error:
  68.             break
  69.  
  70.         
  71.         try:
  72.             val = win32api.RegQueryValue(root, item)
  73.         except win32api.error:
  74.             val = None
  75.  
  76.         ret.append((item, val))
  77.         index = index + 1
  78.     return ret
  79.  
  80. FLAG_RESTRICTED = 1
  81. FLAG_CONTROL = 2
  82. FLAG_HIDDEN = 4
  83.  
  84. def EnumTlbs(excludeFlags = 0):
  85.     '''Return a list of TypelibSpec objects, one for each registered library.
  86. \t'''
  87.     key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib')
  88.     iids = EnumKeys(key)
  89.     results = []
  90.     for iid, crap in iids:
  91.         key2 = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib\\%s' % iid)
  92.         for version, tlbdesc in EnumKeys(key2):
  93.             key3 = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib\\%s\\%s' % (iid, version))
  94.             
  95.             try:
  96.                 flags = int(win32api.RegQueryValue(key3, 'FLAGS'))
  97.             except (win32api.error, ValueError):
  98.                 flags = 0
  99.  
  100.             if flags & excludeFlags == 0:
  101.                 for lcid, crap in EnumKeys(key3):
  102.                     key4 = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib\\%s\\%s\\%s' % (iid, version, lcid))
  103.                     for platform, dll in EnumKeys(key4):
  104.                         if platform == 'win32':
  105.                             major = string.split(version, '.', 1)
  106.                             if len(major) < 2:
  107.                                 major.append('0')
  108.                             
  109.                             
  110.                             try:
  111.                                 (major, minor) = (string.atoi(major[0], 16), string.atoi(major[1], 16))
  112.                                 lcid = string.atoi(lcid, 16)
  113.                             except ValueError:
  114.                                 continue
  115.  
  116.                             spec = TypelibSpec(iid, lcid, major, minor, flags)
  117.                             spec.desc = tlbdesc
  118.                             spec.ver_desc = tlbdesc + ' (' + version + ')'
  119.                             spec.dll = dll
  120.                             results.append(spec)
  121.                         
  122.                     
  123.                 
  124.             
  125.         
  126.     
  127.     return results
  128.  
  129.  
  130. def FindTlbsWithDescription(desc):
  131.     '''Find all installed type libraries with the specified description
  132. \t'''
  133.     ret = []
  134.     items = EnumTlbs()
  135.     for item in items:
  136.         if item.desc == desc:
  137.             ret.append(item)
  138.         
  139.     
  140.     return ret
  141.  
  142.  
  143. def SelectTlb(title = 'Select Library', excludeFlags = 0):
  144.     '''Display a list of all the type libraries, and select one.   Returns None if cancelled
  145. \t'''
  146.     import pywin.dialogs.list as pywin
  147.     items = EnumTlbs(excludeFlags)
  148.     items.sort()
  149.     rc = pywin.dialogs.list.SelectFromLists(title, items, [
  150.         'Type Library'])
  151.     if rc is None:
  152.         return None
  153.     
  154.     return items[rc]
  155.  
  156. if __name__ == '__main__':
  157.     print SelectTlb()
  158.  
  159.